﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reticle.Core;
using BNSharp.BattleNet;
using BNSharp;
using System.Windows.Forms;

namespace MikesTestPlugin
{
    public class Main : IPlugin
    {
        public IHost Host;
        public ToolStripMenuItem myMenu = new ToolStripMenuItem();

        #region IPlugin Members

        public string Author
        {
            get { return "Scope"; }
        }

        public string Name
        {
            get { return "Test Plugin"; }
        }

        public string Description
        {
            get { return "A test plugin"; }
        }

        public string Filename
        {
            get { return "MikesTestPlugin.dll"; }
        }

        public string URL
        {
            get { return "blah.com"; }
        }

        public void Initialize(IHost host)
        {
            Host = host;

            // Create the plugin menu (and submenus)
            EventHandler e = new EventHandler(myMenus_Click);
            myMenu.Text = "Example Plugin";
            myMenu.DropDownItems.Add(PluginFunctions.NewToolMenu("Testing", "Users in Channel", e));
            myMenu.DropDownItems.Add(PluginFunctions.NewToolMenu("Unload", "Unload", e));
            Host.SetPluginMenu(myMenu);

            // loads all necessary Battle.net events (joined channel, user spoke, etc)
            loadEvents();
        }

        public void Unload()
        {
            Host.UnloadPlugin();
            //Host.AddChat("yellow", "[TestPlugin] Unloaded.");
        }

        // handles the click event of each menu item
        void myMenus_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem m = (ToolStripMenuItem)sender;
            switch (m.Name)
            {
                case "Testing":
                    MessageBox.Show("Testing Menu 1");
                    break;
                case "Unload":
                    Unload();
                    break;
            }
        }

        #endregion

        #region BattleNet Events
        #region Load Events
        private void loadEvents()
        {
            Host.Client.JoinedChannel += new ServerChatEventHandler(JoinedChannel);
        }
        #endregion

        // Occurs when the bot joins a channel
        private void JoinedChannel(object sender, ServerChatEventArgs e)
        {
            Host.AddChat("white", "[TestPlugin] Joined Channel.");
        }

        public void UserSpoke(object sender, ChatMessageEventArgs e)
        {
            Host.AddChat("blue", "[Plugin] " + e.Text);
        }
        #endregion
    }
}
